package fr.appliClient.server.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "SERVICE")
public class Service implements AbstractEntity<Long>, Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column
	private String name;

	@ManyToOne
	@JoinColumn(name = "service_fk")
	private Service mother;

	@OneToMany(mappedBy = "mother")
	private List<Service> services;

	@OneToMany(mappedBy = "service")
	private List<Vehicle> vehicles;

	public Service() {

	}

	public Service(String nom) {

		this.name = nom;
	}

	public Long getId() {

		return id;
	}

	public String getNom() {

		return name;
	}

	public void setName(String name) {

		this.name = name;
	}

	public List<Vehicle> getVehicles() {

		return vehicles;
	}

	public void setVehicles(List<Vehicle> vehicles) {

		this.vehicles = vehicles;
	}

	public Service getMother() {

		return mother;
	}

	public void setMother(Service mother) {

		if (mother != null) {
			this.mother = mother;
			if (!mother.getServices().contains(this)) {
				mother.getServices().add(this);
			}
		}
	}

	public List<Service> getServices() {

		return services;
	}

	public void setServices(List<Service> services) {

		this.services = services;
	}

}
